<?php
/**
 * Remove a Partner From a Mission
 * 
 * 
 */
use Hive\Mission\Partner;
use Hive\Ressource;
use Hive\Mission;

$xview = Xview::instance();
$missionid = $xview->val('missionid');
$partnerid = $xview->val('rid');
$remove = $xview->val('remove',false);

if(!empty($partnerid) && !empty($missionid) && $remove)
{
	try {
		$mission = Fox\Dao::load(Mission::className(),$missionid);
		$role = Partner::ROLE_CANDIDATE;
		$partner = $mission->findPartners($missionid.':'.$role.':'.$partnerid);
		$partner->delete();
		Fox\Message::Success(Msg(Hive::BUNDLE,Hive::REMOVE_FROM_MISSION,$partner->contact()->name(),$mission->label()));
	}
	catch(Fox\Object\Exception\Save $e) {
		Fox\Message::Error($e->getMessage());
	}
	catch(Fox\Object\Exception\NotExist $e) {
		Fox\Message::Error($e->getMessage());
	}
	echo $xview->messages(true,true);
	exit;
}